package com.amos.think.adapter.web;

import com.alibaba.cola.dto.MultiResponse;
import com.alibaba.cola.dto.Response;
import com.amos.think.api.IUserService;
import com.amos.think.dto.UserModifyCmd;
import com.amos.think.dto.UserRegisterCmd;
import com.amos.think.dto.data.ReqUserDTO;
import com.amos.think.dto.data.UserUpdateDTO;
import com.amos.think.dto.data.UserVO;
import com.amos.think.dto.query.UserListByParamQuery;
import com.amos.think.dto.query.UserLoginQuery;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 用户相关
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private IUserService userService;


    @GetMapping(value = "/hello")
    public String hello() {
        return "Hello";
    }

    /**
     * 用户新增接口
     * @param cmd
     * @return
     */
    @PostMapping(value = "/register")
    public Response register(@RequestBody UserRegisterCmd cmd) {
        userService.register(cmd);
        return Response.buildSuccess();
    }

    /**
     * 查询所有用户列表接口
     * @param name
     * @return
     */
    @GetMapping(value = "/list")
    public MultiResponse<UserVO> list(@RequestParam(required = false) String name) {
        return userService.listByName(UserListByParamQuery.builder().name(name).build());
    }

    /**
     * 用户信息删除接口
     * @param reqUserDTO
     * @return
     */
    @PostMapping("/deleteById")
    public Response deleteByUserId(@RequestBody ReqUserDTO reqUserDTO, HttpServletRequest httpServletRequest){
        String userId = httpServletRequest.getHeader("userId");
        userService.deleteByUserId(reqUserDTO.getUserId(),userId);
        return Response.buildSuccess();
    }

    /**
     * 用户信息修改接口
     */
    @PostMapping("/updateById")
    public UserVO updateById(@RequestBody UserModifyCmd userModifyCmd){
        UserVO userVO = userService.modify(userModifyCmd);
        return userVO;
    }

//    @PostMapping(value = "/login")
//    public Response login(@RequestBody UserLoginQuery userLoginQuery) {
//        userService.login(userLoginQuery);
//        return Response.buildSuccess();
//    }


}

